local zhenfu = fk.CreateSkill{
    name = "jin_heg__zhefu",
}

Fk:loadTranslationTable{
    ["jin_heg__zhefu"] = "哲妇",
    [":jin_heg__zhefu"] = "当你于回合外使用或打出基本牌结算后，你可观看一名势力角色数不小于你的角色的所有手牌，然后你可弃置其中一张基本牌。",
    ["#jin_heg__zhefu-invoke"] = "哲妇：选择一名角色，观看其手牌",
    ["#jin_heg__zhefu-card"] = "哲妇：你可弃置其中一张基本牌",

    ["$jin_heg__zhefu1"] = "非我善妒，实乃汝之过也！",
    ["$jin_heg__zhefu2"] = "履行不端者，当有此罚。",
}

local H = require "packages.ol_hegemony.util"

zhenfu:addEffect(fk.CardUseFinished,{
    anim_type = "control",
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(zhenfu.name) and player == target and player.phase == Player.NotActive and data.card.type == Card.TypeBasic
      end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local x = H.getKingdomPlayersNum(room)[H.getKingdom(player)]
        local targets = table.filter(room.alive_players, function (p)
          return not p:isKongcheng() and (H.getKingdomPlayersNum(room)[H.getKingdom(p)] or 1) >= x
        end)
        if #targets == 0 then return end
        local to = room:askToChoosePlayers(player,{
            targets = targets,
            min_num = 1,
            max_num = 1,
            prompt = "#jin_heg__zhefu-invoke",
            skill_name = zhenfu.name,
            cancelable = false,
        })[1]
        local allcards = to:getCardIds("h")
        local cards = table.filter(allcards, function (cid)
          return Fk:getCardById(cid).type == Card.TypeBasic
        end)
        local card, _ = room:askToChooseCardsAndChoice(player, {
          cards = cards,
          choices = {"OK"},
          skill_name = zhenfu.name,
          prompt = "#jin_heg__zhefu-card",
          min_num = 0,
          max_num = 1,
          all_cards = allcards,
        })
        if #card > 0 then
          room:throwCard(card, zhenfu.name, to, player)
       end
      end,
})

zhenfu:addEffect(fk.CardRespondFinished,{
    anim_type = "control",
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(zhenfu.name) and player == target and player.phase == Player.NotActive and data.card.type == Card.TypeBasic
      end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local x = H.getKingdomPlayersNum(room)[H.getKingdom(player)]
        local targets = table.filter(room.alive_players, function (p)
          return not p:isKongcheng() and (H.getKingdomPlayersNum(room)[H.getKingdom(p)] or 1) >= x
        end)
        if #targets == 0 then return end
        local to = room:askToChoosePlayers(player,{
            targets = targets,
            min_num = 1,
            max_num = 1,
            prompt = "#jin_heg__zhefu-invoke",
            skill_name = zhenfu.name,
            cancelable = false,
        })[1]
        local allcards = to:getCardIds("h")
        local cards = table.filter(allcards, function (cid)
          return Fk:getCardById(cid).type == Card.TypeBasic
        end)
        local card, _ = room:askToChooseCardsAndChoice(player, {
          cards = cards,
          choices = {"OK"},
          skill_name = zhenfu.name,
          prompt = "#jin_heg__zhefu-card",
          min_num = 0,
          max_num = 1,
          all_cards = allcards,
        })
        if #card > 0 then
          room:throwCard(card, zhenfu.name, to, player)
        end
      end,
})

return zhenfu